//
//  UIColor+YsTools.m
//  YsToolsManager
//
//  Created by 宋宏康 on 2020/10/18.
//

#import "UIColor+YsTools.h"
#import <YYCategories/YYCategories.h>

@implementation UIColor (YsTools)

+ (UIColor *)randomColor
{
    CGFloat red = ( arc4random() % 255 / 255.0 );
    CGFloat green = ( arc4random() % 255 / 255.0 );
    CGFloat blue = ( arc4random() % 255 / 255.0 );
    return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}


+ (UIColor *)colorFromColor:(UIColor *)fromColor
                    toColor:(UIColor *)toColor
                   progress:(CGFloat)progress
{
    progress = MIN(progress, 1.0f);
    CGFloat fromRed = fromColor.red;
    CGFloat fromGreen = fromColor.green;
    CGFloat fromBlue = fromColor.blue;
    CGFloat fromAlpha = fromColor.alpha;
    
    CGFloat toRed = toColor.red;
    CGFloat toGreen = toColor.green;
    CGFloat toBlue = toColor.blue;
    CGFloat toAlpha = toColor.alpha;
    
    CGFloat finalRed = fromRed + (toRed - fromRed) * progress;
    CGFloat finalGreen = fromGreen + (toGreen - fromGreen) * progress;
    CGFloat finalBlue = fromBlue + (toBlue - fromBlue) * progress;
    CGFloat finalAlpha = fromAlpha + (toAlpha - fromAlpha) * progress;
    
    return [UIColor colorWithRed:finalRed green:finalGreen blue:finalBlue alpha:finalAlpha];
}
@end
